﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CategoryView.aspx.cs" Inherits="Directory.Web.Admin_CategoryView"
    Theme="Admin_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script type="text/javascript" src="../JS/jquery-1.3.2.min.js"></script>

    <script type="text/javascript" src="../JS/dragsort-0.3.7.min.js"></script>

    <script type="text/javascript" src="../JS/jquery.loadmask.min.js"></script>

    <script type="text/javascript">
        function NavUrl(url) {
            location.href = url;
        }
        function SelectAll(obj) {
            var checkList = document.getElementsByName("child_Id");
            if (checkList.length == 0) {
                return;
            }
            for (var i = 0; i < checkList.length; i++) {
                checkList[i].checked = obj.checked;
            }
        }
        function BathDelete(url) {
            var idlist = "";
            var checkList = document.getElementsByName("child_Id");
            if (checkList.length == 0) {
                return;
            }
            for (var i = 0; i < checkList.length; i++) {
                if (checkList[i].checked) {
                    idlist += checkList[i].value + ",";
                }
            }
            if (idlist.length == 0) {
                alert("请选择要删除的项");
                return;
            }
            if (confirm('确认删除所选分类吗？将删除所有子分类及其条文。')) {
                url += "&idlist=" + idlist;
                NavUrl(url);
            }
        }
        function GotoCategory(id) {
            if (parent != null) {
                //                top.RefreshNodeTree(id);
                parent.location.href = "categorydetails.aspx?categoryId=" + id;
            } else {
                location.href = "categorydetails.aspx?categoryId=" + id;
            }
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div class="container">
        <div class="pageheader">
            <%= Resources.Resource.Category %>:
            <asp:Literal ID="ltPath" runat="server"></asp:Literal>
            <b style="color: Red;">
                <% = this.cat.CategoryName%></b>
            <div style="float: right">
                <asp:HyperLink ID="hplExport" runat="server" Target="_blank">导出数据</asp:HyperLink></div>
        </div>
        <div class="pagecontent">
            <asp:Repeater ID="rptChilds" runat="server">
                <HeaderTemplate>
                    <ul id="childlist" style="width: 100%; display: block;">
                </HeaderTemplate>
                <ItemTemplate>
                    <li id="drog" itemid="<%# Eval("CategoryId")%>">
                        <input name="child_Id" type="checkbox" value="<%# Eval("CategoryId")%>" />&nbsp;
                        <span title="拖动排序" class="col_Drag">
                            <!--%# Eval("Order")%-->
                        <img src="../imgs/folder.gif" alt="拖动" />
                        </span><span class="col_CatName"><a title="单击查看" target="_parent" href='categorydetails.aspx?<% =this.categoryIdKey %>=<%# Eval("CategoryId")%>'>
                            <%# Eval("CategoryName")%></a></span></li>
                </ItemTemplate>
                <FooterTemplate>
                    </ul>
                </FooterTemplate>
            </asp:Repeater>
            <center style="clear: both; padding: 20px 0;">
                <input type="checkbox" value="全选" onclick="SelectAll(this)" />&nbsp;全选&nbsp; &nbsp;
                <input type="button" class="input_Button" onclick="BathDelete('category.aspx?action=batchdelete&<% =this.categoryIdKey %>=<% = Request.QueryString[categoryIdKey] %>')"
                    value='删除所选' />&nbsp; &nbsp;
                <input type="button" class="input_Button" onclick="NavUrl('category.aspx?action=addchilds&<% =this.categoryIdKey %>=<% = Request.QueryString[categoryIdKey] %>')"
                    value='添加<% =Resources.Resource.ResourceManager.GetString("ChildCategory")%>' />
                &nbsp; &nbsp;
                <input type="button" class="input_Button" onclick="NavUrl('category.aspx?action=batchadd&<% =this.categoryIdKey %>=<% = Request.QueryString[categoryIdKey] %>')"
                    value='批量添加<% =Resources.Resource.ResourceManager.GetString("ChildCategory")%>' />
                &nbsp; &nbsp;
                <% if (this.cat.ParentCategoryId != Directory.Web.WebSettings.GetInstance().RootCategoryId)
                   { %>
                <input type="button" class="input_Button" onclick="NavUrl('category.aspx?action=modify&<% =this.categoryIdKey %>=<% = Request.QueryString[categoryIdKey] %>')"
                    value='编辑<% =Resources.Resource.ResourceManager.GetString("Category")%>' />&nbsp;
                &nbsp;
                <% }
                   else
                   { %>
                <DirectoryControl:RolePanel runat="server" ID="RolePanel1">
                    <input type="button" class="input_Button" onclick="NavUrl('category.aspx?action=modify&<% =this.categoryIdKey %>=<% = Request.QueryString[categoryIdKey] %>')"
                        value='编辑<% =Resources.Resource.ResourceManager.GetString("Category")%>' />&nbsp;
                    &nbsp;
                </DirectoryControl:RolePanel>
                <% } %>
                <input type="button" class="input_Button" onclick="if(confirm('确认要删除该分类吗？将删除所有子分类及其条文。')){NavUrl('category.aspx?action=delete&<% =this.categoryIdKey %>=<% = Request.QueryString[categoryIdKey] %>')}"
                    value='删除<% =Resources.Resource.ResourceManager.GetString("Category")%>' />
                &nbsp; &nbsp;
            </center>
        </div>
    </div>
    </form>

    <script type="text/javascript">
        function SetLineColor() {
            $('#childlist li').css({ 'background-color': '#cde5ff' });
            //            $('#childlist li:even').css({ 'background-color': '#cde5ff' });
            //            $('#childlist li:odd').css({ 'background-color': '#FFFFFF' });
        }
        $('#childlist').dragsort({ dragSelector: ".col_Drag", dragEnd: saveOrder, placeHolderClass: "dragClass", placeHolderTemplate: "<li></li>" });
        var rawSerialStr = "";
        $("#childlist li").each(function(i, elm) { rawSerialStr += (i > 0 ? "|" : "") + $(elm).attr("itemID"); });
        function saveOrder() {
            var serialStr = "";
            $("#childlist li").each(function(i, elm) { serialStr += (i > 0 ? "|" : "") + $(elm).attr("itemID"); });
            if (serialStr == rawSerialStr) {
                return;
            }
            rawSerialStr = serialStr;
            // $.ajax({ url: "Category.aspx?action=setorder&ids=" + serialStr, type: "GET" });
            $('.container').mask("正在保存数据，请稍候...");
            $.get("Category.aspx?action=setorder&ids=" + serialStr, function(data) { $('.container').unmask(); SetLineColor(); location.reload(); alert(data); });
        };
        SetLineColor();
    </script>

</body>
</html>
